<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    /*
        1
     */
    let singleton = function () { // 私有变量和私有函数
        let privateVariable = 10;

        function privateFunction() {
            return false;
        }

        // 创建对象
        let object = new CustomType();
        // 添加特权/公有属性和方法 
        object.publicProperty = true;
        object.publicMethod = function () {
            privateVariable++;
            return privateFunction();
        };
        // 返回对象
        return object;
    }();

    /*
        2
     */

    let application = function () { // 私有变量和私有函数
        let components = new Array();
        // 初始化
        components.push(new BaseComponent());
        // 创建局部变量保存实例
        let app = new BaseComponent();
        // 公共接口
        app.getComponentCount = function () {
            return components.length;
        };
        app.registerComponent = function (component) {
            if (typeof component == "object") {
                components.push(component);
            }
        };
// 返回实例
        return app;
    }();
</script>
</body>
</html>